# $Id: Makefile.in 756 2007-04-30 07:08:01Z cromain $

CC = gcc
CFLAGS = -g -O2
CPPFLAGS = -I/usr/local/ssl/lib 
LDFLAGS = 
LIBS = 

EXPAT_CFLAGS = 
ERLANG_CFLAGS= -I/usr/lib/erlang/lib/erl_interface-3.5.5.3/include -I/usr/lib/erlang/usr/include

EXPAT_LIBS =  -lexpat
ERLANG_LIBS = -L/usr/lib/erlang/lib/erl_interface-3.5.5.3/lib -lerl_interface -lei

# make debug=true to compile Erlang module with debug informations.
ifdef debug
  ERLC_FLAGS+=+debug_info
endif

ifdef ejabberd_debug
  ERLC_FLAGS+=-Dejabberd_debug
endif

ifeq (false, true)
  ERLC_FLAGS+=-DROSTER_GATEWAY_WORKAROUND
endif

prefix = 

SUBDIRS = mod_irc mod_pubsub mod_muc eldap web stringprep tls  ejabberd_zlib
ERLSHLIBS = expat_erl.so
SOURCES = $(wildcard *.erl)
BEAMS = $(SOURCES:.erl=.beam)

DESTDIR = 

EJABBERDDIR = $(DESTDIR)/var/lib/ejabberd
BEAMDIR = $(EJABBERDDIR)/ebin
PRIVDIR = $(EJABBERDDIR)/priv
SODIR = $(PRIVDIR)/lib
MSGSDIR = $(PRIVDIR)/msgs
LOGDIR = $(DESTDIR)/var/log/ejabberd
ETCDIR = $(DESTDIR)/etc/ejabberd

ASN_FLAGS = -bber_bin +der +compact_bit_string +optimize +noobj

ifeq ($(shell uname),Darwin)
DYNAMIC_LIB_CFLAGS = -fPIC -bundle -flat_namespace -undefined suppress
else
# Assume Linux-style dynamic library flags
DYNAMIC_LIB_CFLAGS = -fpic -shared
endif

all: $(ERLSHLIBS) compile-beam all-recursive

compile-beam: XmppAddr.hrl $(BEAMS)

%.beam:       %.erl
	/usr/bin/erlc -W $(ERLC_FLAGS) $<


all-recursive install-recursive uninstall-recursive \
clean-recursive distclean-recursive \
mostlyclean-recursive maintainer-clean-recursive:
	@subdirs="$(SUBDIRS)"; for subdir in $$subdirs; do \
	target=`echo $@|sed 's,-recursive,,'`; \
	echo making $$target in $$subdir; \
	(cd $$subdir && $(MAKE) $$target) || exit 1; \
	done


%.hrl: %.asn1
	/usr/bin/erlc $(ASN_FLAGS) $<

$(ERLSHLIBS):	%.so:	%.c
			gcc -Wall $(CFLAGS) $(LDFLAGS) $(LIBS) \
			$(subst ../,,$(subst .so,.c,$@)) \
			$(EXPAT_LIBS) $(EXPAT_CFLAGS) \
			$(ERLANG_LIBS) $(ERLANG_CFLAGS) \
			-o $@ $(DYNAMIC_LIB_CFLAGS)

install: all
	install -d $(BEAMDIR)
	install -m 644 *.beam $(BEAMDIR)
	rm -f $(BEAMDIR)/configure.beam
	install -m 644 *.app $(BEAMDIR)
	install -d $(SODIR)
	install -m 644 *.so $(SODIR)
	install -d $(MSGSDIR)
	install -m 644 msgs/*.msg $(MSGSDIR)
	install -d $(ETCDIR)
	[ -f $(ETCDIR)/ejabberd.cfg ] && install -b -m 644 ejabberd.cfg.example $(ETCDIR)/ejabberd.cfg-new || install -b -m 644 ejabberd.cfg.example $(ETCDIR)/ejabberd.cfg
	install -d $(LOGDIR)

clean: clean-recursive clean-local

clean-local:
	rm -f *.beam $(ERLSHLIBS)
	rm -f XmppAddr.asn1db XmppAddr.erl XmppAddr.hrl

distclean: distclean-recursive clean-local
	rm -f config.status
	rm -f config.log
	rm -f Makefile

TAGS:
	etags *.erl

Makefile: Makefile.in
